package com.codegzy.controller;

import com.codegzy.entity.Admin;
import com.codegzy.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("register")
    public String register(Admin admin){
        if (admin != null){
            adminService.register(admin);
            return "login";
        }else {
            return "redirect:/regist.jsp";
        }
    }

    @RequestMapping("login")
    public String login(Admin admin, HttpServletRequest request){
        String login = adminService.login(admin);
        request.getSession().setAttribute("login",login);
        if (login != null){
            return "redirect:/emp/findAll";
        }else{
            return "redirect:/login.jsp";
        }
    }
}
